﻿using Microsoft.Graphics.Canvas;
using Microsoft.Graphics.Canvas.Effects;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using Windows.UI;

namespace 纸片人.win2dEffectControl.DataClass
{
    public class ChromaKeyEffectData : EffectOneSourceData
    {
        #region 属性
        private Color _color = Colors.Black;
        private Vector4 _colorHdr = new Vector4(0,0,0,1);
        private bool _feather = false;
        private bool _invertAlpha = false;
        private float _tolerance = 0.1f;

        public float Tolerance { get => _tolerance; set { _tolerance = value;OnPropertyChanged();SetIsChanges(); } }
        public bool InvertAlpha { get => _invertAlpha; set{ _invertAlpha = value; OnPropertyChanged(); SetIsChanges(); } }
        public bool Feather { get => _feather; set{ _feather = value; OnPropertyChanged(); SetIsChanges(); } }
        public Vector4 ColorHdr { get => _colorHdr;set { _colorHdr = value; OnPropertyChanged(); SetIsChanges(); } }
        public Color Color { get => _color; set { _color = value; OnPropertyChanged(); SetIsChanges(); } }
        #endregion

        public override ICanvasImage GetEffect(CanvasDevice device, bool compression)
        {
            var source = GetSourceEffect(device, compression);
            if(source == null)
            {
                return null;
            }
            var cke = new ChromaKeyEffect();
            ChromaKeyEffect effect = new ChromaKeyEffect()
            {
                Color = Color,
                ColorHdr = ColorHdr,
                Feather = Feather,
                InvertAlpha = InvertAlpha,
                Tolerance = Tolerance,
                Source =source

            };
            return effect;
                 
        }
    }
}
